/**
 * <p>Copyright:Copyright(c) 2019</p>
 * <p>Company:Professional</p>
 * <p>Package:org.cesgroup.course.autoconfigure</p>
 * <p>File:Ch003AutoConfiguration.java</p>
 * <p>类更新历史信息</p>
 * @todo chanlong(陈龙) 创建于 Sep 12, 2019 12:50:35 PM
 */
package com.ces.autoconfigure;

import com.ces.chain.Interceptor;
import com.ces.chain.ProxyChain;
import com.ces.converter.Converter;
import com.ces.converter.SimpleConverter;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
@ConfigurationProperties(prefix = "ces.resources")
public class AutoConfiguration {

	private final Interceptor[] interceptors;
	private final ProxyChain<Converter> proxyChain = new ProxyChain<>();
	
	// 项目启动时，向“代理责任链”添加“Interceptor”实例
	public AutoConfiguration(ObjectProvider<Interceptor[]> provider) {
		this.interceptors = provider.getIfAvailable();
		for (Interceptor interceptor : interceptors) {
			proxyChain.addInterceptor(interceptor);
		}
	}
	
	// 加载所有代理对象，设置目标对象，创建目标对象的bean
	@Bean
	public Converter converter() {
		return proxyChain.all(new SimpleConverter());
	}
	
	private String staticLocation;

	public String getStaticLocation() {
		return staticLocation;
	}

	public void setStaticLocation(String staticLocation) {
		this.staticLocation = staticLocation;
	}
	
}
